package com.qing;

import java.util.Arrays;
import java.util.List;
import java.util.function.IntSupplier;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Demo2 {
    public static void main(String[] args) {
       /* List<Integer> numbers= Arrays.asList(1,2,3,4,5);
        int count=numbers.stream().reduce(0,(a,b)->a+b);
        System.out.println(count);

        numbers.stream().reduce(0,Integer::sum);


        numbers.stream().reduce(Integer::max);
        numbers.stream().reduce(Integer::min);

        numbers.stream().map(d->1).reduce(0,(a,b)->a+b);
        numbers.stream().count();


        Stream.iterate(0,n->n+2).limit(10).forEach(System.out::println);

        Stream.iterate(new int[]{0,1},t->new int[]{t[1],t[0]+t[1]}).limit(20).forEach(t-> System.out.println("("+t[0]+","+t[1]+")"));

        Stream.generate(Math::random).limit(5).forEach(System.out::println);*/


        IntSupplier fil=new IntSupplier() {

            private int previous=0;
            private int current=1;
            @Override
            public int getAsInt() {
                int oldPrevious=this.previous;
                int nextValue=this.previous+this.current;
                this.previous=this.current;
                this.current=nextValue;
                return oldPrevious;
            }
        };

        IntStream.generate(fil).limit(10).forEach(System.out::println);
    }
}
